﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Scoreboard.Model;
using Microsoft.Scripting.Hosting;
using IronRuby;

namespace Scoreboard.Scripting
{
	public class ScriptExecutor
	{
		private ScriptScope _scope;
		private ScriptEngine _engine;

		public ScriptExecutor()
		{
			_engine = Ruby.CreateEngine();
			_scope = _engine.CreateScope();
		}

		public void Run(Tournament tournament, string script)
		{	
			_scope.SetVariable("t", tournament);
			_scope.SetVariable("f", new Factory());
			_scope.SetVariable("h", new Helper());

			try
			{
				_engine.Execute(script, _scope);
			}
			catch (Exception e)
			{
				//System.Diagnostics.Debug.WriteLine(e.Message);
			}
		}
	}
}
